<template>
	<view class="wrap">
		<view class="content">
			<view class="cont">
				<view class="top">
					
			<view class="header_img">
			    <image :src="info.avatar" mode=""></image>
			</view>
					
					<view class="detail">
						<view class="name">{{info.nickname}}</view>
					<!-- 	<text>{{}}</text> -->
					</view>
				</view>
				<view class="commend">
					<view class="text">我的推荐码</view>
					<text>{{info.invate_code}}</text>
				</view>
				<view class="erweima">
					<!-- <uqrcode size="150" ref="uqrcode" canvas-id="qrcode"
						:value="`https://www.yuexiangshidai.cn/web/index.html#/pages/login/register?invate_code=${info.invate_code}`">
					</uqrcode> -->
					<image :src="code" mode=""></image>
				</view>
				<view class="bottom">
					<view class="text">扫描上方二维码</view>
					<text>长按二维码保存到手机或微信识别二维码</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import {
	makeQrcode,
		user
	} from '@/api/index.js'

	export default {
		data(){
			return{
				info: {},
				code: ''
			}
		},
		onLoad () {
			this.getInfo()
			this.getCode()
		},
		onShow() {
		    this.getInfo();
		    const accountId = this.info.id; 
		   const cachedAvatarUrl = uni.getStorageSync('avatarUrl');
		    if (cachedAvatarUrl) {
		        this.seleUrl = cachedAvatarUrl;
		    } else {
		        this.seleUrl = '/static/img/tabbar/mine.png';
		    }
		},
		
		methods:{
			async getInfo() {
			let res = await user();
			    this.info = res.data;
			    const cachedAvatarUrl = uni.getStorageSync('avatarUrl'); 
			    console.log('从缓存中读取的头像:', cachedAvatarUrl); 
			    if (cachedAvatarUrl) {
			        this.info.avatar = cachedAvatarUrl; 
			    } else {
			        this.info.avatar = res.data.avatar; 
			    }
			},
			
			async getCode() {
				let res = await makeQrcode()
				this.code = res.data
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		
		.content {
			padding: 100rpx 48rpx 0;
			box-sizing: border-box;
			
			.cont {
				height: fit-content;
				padding: 40rpx;
				border-radius: 12rpx;
				background-color: #fff;
				border: 14rpx solid #F88EAA;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				align-items: center;
				
				.top {
					width: 100%;
					display: flex;
					align-items: center;
					margin-bottom: 28rpx;
					
					.header_img {
						width: 100rpx;
						height: 100rpx;
						border-radius: 100%;
						margin-right: 40rpx;
						border: 6rpx solid #F88EAA;
						box-sizing: border-box;
						
						image {
							width: 100%;
							height: 100%;
							border-radius: 100%;
						}
					}
					
					.detail {
						display: flex;
						flex-direction: column;
						
						.name {
							font-size: 28rpx;
							font-weight: bold;
							margin-bottom: 14rpx;
						}
						
						text {
							font-size: 24rpx;
						}
					}
				}
				
				.commend {
					display: flex;
					flex-direction: column;
					align-items: center;
					margin-bottom: 18rpx;
					
					.text {
						width: fit-content;
						height: 54rpx;
						background-color: #F42B57;
						border-radius: 0 0 32rpx 0;
						color: #fff;
						line-height: 54rpx;
						font-size: 24rpx;
						padding: 0 52rpx;
						box-sizing: border-box;
						margin-bottom: 44rpx;
					}
					
					text {
						font-size: 40rpx;
						color: #F3302F;
						font-weight: 500;
					}
				}
				
				.erweima {
					width: 300rpx;
					height: 300rpx;
					
					margin-bottom: 48rpx;
					
					image {
						width: 100%;
						height: 100%;
					}
				}
				
				.bottom {
					display: flex;
					flex-direction: column;
					align-items: center;
					
					.text {
						font-size: 40rpx;
						font-weight: 500;
						margin-bottom: 8rpx;
					}
					
					text {
						font-size: 28rpx;
						color: #A0A0A0;
					}
				}
			}
		}
	}
</style>